﻿
#region Copyright & License
// --------------------------
// Copyright 2008 Daniel Gray
// --------------------------
// This file is part of Kale.
//
// Kale is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Kale is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Kale.  If not, see <http://www.gnu.org/licenses/>.
#endregion
#region File details
// --------------------------------------------------------
// Filename          : SecurityBehaviorExtensionElement.cs
// Author            : Daniel Gray
// Created           : 29/04/2008
// --------------------------------------------------------
#endregion
            
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Configuration;
using System.Configuration;

namespace Kale.Web.Services.Behaviours
{
   public class SecurityBehaviorExtensionElement : BehaviorExtensionElement
   {
      private ConfigurationPropertyCollection _properties; 

      [ConfigurationProperty("cookieName", DefaultValue = "sessionUid", IsRequired = false)]
      public string CookieName
      {
         get { return (string)base["cookieName"]; }
         set { base["cookieName"] = value; }
      }

      public override Type BehaviorType
      {
         get { return typeof(SecurityBehavior); }
      }

      protected override object CreateBehavior()
      {
         return new SecurityBehavior(CookieName);
      }

      protected override ConfigurationPropertyCollection Properties
      {
         get
         {
            if (_properties == null)
            {
               _properties = new ConfigurationPropertyCollection();
               _properties.Add(new ConfigurationProperty(
                  "cookieName", typeof(string), "sessionUid",
                  ConfigurationPropertyOptions.None
                  ));
            }
            return _properties;
         }
      }

      public override void CopyFrom(ServiceModelExtensionElement from)
      {
         base.CopyFrom(from);
         SecurityBehaviorExtensionElement element = (SecurityBehaviorExtensionElement)from;
         CookieName = element.CookieName;
      }
   }
}
